package com.yi.apipassenger.service;

import com.yi.apipassenger.remote.ServicePassengerUserClient;
import com.yi.internalcommon.constant.CommonStatusEnum;
import com.yi.internalcommon.dto.PassengerUser;
import com.yi.internalcommon.dto.ResponseResult;
import com.yi.internalcommon.dto.TokenResult;
import com.yi.internalcommon.request.VerificationCodeDTO;
import com.yi.internalcommon.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private ServicePassengerUserClient servicePassengerUserClient;
    public ResponseResult getUserByAccessToken(String accessToken){
        //解析accesstoken
        TokenResult tokenResult = JwtUtils.checkToken(accessToken);
        if(tokenResult==null){
         return  ResponseResult.fail(CommonStatusEnum.TOKEN_ERROR.getCode(),CommonStatusEnum.TOKEN_ERROR.getValue());
        }
        String phone = tokenResult.getPhone();
        //根据手机号查询用户信息
        ResponseResult result = servicePassengerUserClient.getUser(phone);
        return  result;
    }


}
